#include<bits/stdc++.h>
#define int long long
#define N 1005
using namespace std;
int n,a[N],b[N];
set<vector<int> >s;
vector<int> x;
void dfs(int i,int j){
	if(i==n&&j==n){s.insert(x);return;}
	if(i<n)x.push_back(b[j]),dfs(i+1,j),x.pop_back();
	if(j<n)x.push_back(a[i]),dfs(i,j+1),x.pop_back();
}
signed main(){
	freopen("zha.in","r",stdin);
	freopen("zha.out","w",stdout);
	cin.tie(0)->sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	dfs(1,1);
	cout<<s.size()<<'\n';
	return 0;
}